package org.point.dao.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductInOutDao;
import org.point.domain.ProductInOut;
import org.point.domain.ProductType;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: ProductInOutDaoImpl
 * @Description: TODO(商品进出数据实现类)
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:43:44
 *
 */
@Repository("productInOutDao")
public class ProductInOutDaoImpl extends BaseDaoImpl<ProductInOut, Serializable> implements ProductInOutDao {

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>
	 * Title:
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 */
	public ProductInOutDaoImpl() {
		namespace = super.getNamespace();
	}

	// 查询商品进出信息列表
	public static final String SQLID_SEARCHPIO = "search_PIO";
	// 新增商品进出信息
	public static final String SQLID_INSERTPIO = "insert_PIO";

	public static final String SQLID_SEARCHPIOPAGE = "search_pio_page";
	
	public static final String SQLID_SEARCH_PIO_COUNT = "search_pio_count";
	
	public static final String SQLID_DEL_PIO = "del_fro_id";
	
	private static final String SQLID_SEARCHFORID = "search_for_id";

	public List<ProductInOut> searchPIO(Map<String, Object> map) {
		List<ProductInOut> records = getSqlSession().selectList(namespace + SQLID_SEARCHPIO, map);
		return records;
	}

	public Integer insertPIO(ProductInOut record) {
		Integer result = getSqlSession().insert(namespace + SQLID_INSERTPIO, record);
		return result;
	}

	// 查询商品进出页面信息
	public List<ProductInOut> searchPIOInfo(DoPage<ProductInOut> page) {
		List<ProductInOut> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_SEARCHPIOPAGE, page);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return records;
	}

	// 查询记录总数
	public Integer searchPIOCount(DoPage<ProductInOut> page) {

		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_SEARCH_PIO_COUNT, page);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return result;
	}
	
	public Integer delPIO(Map<String, Object> map){
		Integer result =0;
		try {
			result= getSqlSession().update(namespace + SQLID_DEL_PIO, map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	public ProductInOut searchForId(Map<String, Object> map) {
		// TODO Auto-generated method stub
		try {
			ProductInOut records=null;
			records =getSqlSession().selectOne(namespace + SQLID_SEARCHFORID, map);
			return records;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException("根据ID查询商品进出数据数错误！", e);
		}
	}
	

}
